package 算法.tanxin;

/**
 * 最长有效子串
 * @author lchenglong
 * @date 2022/3/4
 */
public class Yxzc {

    public static void main(String[] args) {
        String str = "()()((()))((";
        System.out.println(max(str));

    }

    public static int  max(String str){
        if (str == null || str.length() ==0){
            return 0;
        }

        int minLeft = 0,maxRight = 0,len = str.length();
        for (int i=0;i<len;i++){
            if (str.charAt(i) == '('){
                minLeft = Math.min(minLeft,i);
            } else {
                maxRight = Math.max(maxRight,i);
            }
        }
        return maxRight-minLeft+1;

    }
}
